package com.itnoob.demo3;

import java.util.HashMap;
import java.util.Map;

/**
 * 定义一个SimpleBeanFactory类,表示享元工厂
 * @author zhoujun
 * @date 2025/3/21 22:13
 */
public class SimpleBeanFactory {

    private final Map<String,Object> beanMap = new HashMap<>();

    public Object getBean(String name){
        Object bean = beanMap.get(name);
        if (bean == null){
             bean = new HelloServiceImpl(name);
            System.out.println("创建了"+name);
            beanMap.put(name,bean);
        }
        return bean;
    }
}
